﻿using System;

namespace KryptecizerBase.Encryption
{
    /// <summary>
    /// Encryptor for TextBasedKryptOjects.
    /// </summary>
    public abstract class KryptoTextEncryptor : Encryptor
    {
        #region Member
        protected KryptoText _KryptoText;
        #endregion

        #region Properties
        /// <summary>
        /// Gets or sets the encrypted krypto text.
        /// </summary>
        /// <value>The encrypted krypto text.</value>
        public KryptoText EncryptedKryptoText
        {
            get { return _KryptoText; }
            set { _KryptoText = value; }
        }
        #endregion

        #region Constructor
        /// <summary>
        /// Initializes a new instance of the <see cref="KryptoTextEncryptor"/> class.
        /// </summary>
        public KryptoTextEncryptor()
        {
            _KryptoText = new KryptoText();
        }
        #endregion

        #region public methods
        /// <summary>
        /// Implementation of abstract dencryption method.
        /// Calls OnEncryptionStartet and OnEncryptionEnded methods.
        /// Uses abstract protected Encrypt method.
        /// </summary>
        public override void Encrypt()
        {
            OnEncryptionStartet();
            bool result = Encrypt(_KryptoText.Clone());
            OnEncryptionEnded(result);
        }
        #endregion

        #region abstract methods
        /// <summary>
        /// Abstract method to encrypt the specified krypto text.
        /// </summary>
        /// <param name="kryptoText">The krypto text.</param>
        /// <returns>success</returns>
        protected abstract bool Encrypt(KryptoText kryptoText);
        #endregion
    }
}
